<template>
  <section v-if="files && files.length>0">
    <p class="line"></p>
    <section class="pdv-3">
      <div class="pdv-0 pdh-5 mgt-4 title bold" style="font-size:15PX;">附件：</div>
      <ul class="list-file">
        <li class="item" @click="download(item)" v-for="(item,index) in files">
          {{index + 1}}、{{item.fileName}}  <span class="color-tip pull-right">点击下载</span></li>
      </ul>
    </section>
  </section>
</template>

<script>
  export default {
    props: ['contentId'],
    name: 'fileDownloadComponent',
    data () {
      return {
        files:[]
      }
    },
    created () {
      this.newsFiles()
    },
    methods: {
      newsFiles(){
        this.fetchService.newsFiles(this.contentId).then(res => {
          if (res.code !== 0) {
            // return this.tools.tip(res.message)
            return false
          }
          if(res.data && res.data.length>0){
            this.files = res.data
          }

          // console.log('this.files',this.files);
        })
      },
      download (item) {
        if(this.tools.indexOfHttp(item.fileOssUrl)){
          this.tools.nativeDownLoad(item.fileOssUrl, item.fileName)
        }else{
          this.tools.nativeDownLoad( this.tools.getImgUrl(item.fileId), item.fileName)
        }
        // this.tools.nativeDownLoad(item.fileUrl, item.fileName)
      }
    }
  }
</script>

<style scoped lang="scss">
</style>
